package edu.pdx.LAMA.AndroidCourse.scheduler;

import android.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.RingtoneManager;
import android.net.Uri;
import android.util.Log;

public class AlarmReceiver extends BroadcastReceiver{

	private final static String TAG = "Alarm Receiver";
	public final static String EXTRA_TITLE = "edu.pdx.LAMA.AndroidCourse.scheduler.AlarmReceiver.title";
	public final static String EXTRA_CONTENT = "edu.pdx.LAMA.AndroidCourse.scheduler.AlarmReceiver.content";
	@SuppressWarnings({ "deprecation", "static-access" })
	@Override
	public void onReceive(Context context, Intent intent) {
		// TODO Auto-generated method stub
		Log.d("yoyo", "hahahaha");
		
		Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
		
		String title = intent.getStringExtra(EXTRA_TITLE);
		String content = intent.getStringExtra(EXTRA_CONTENT);
		if (title != null && content != null){
			Log.d(TAG, "Title: "+title+" Content: "+content);
		} else {
			Log.d(TAG, "Title and content are null");
		}
		
		NotificationManager nFm;
		nFm = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
		
		//@SuppressWarnings("deprecation")
		Notification notification = new Notification(R.drawable.arrow_down_float, "Scheduler: "+title, System.currentTimeMillis());
		notification.sound = uri;
		
		PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, ScheduleActivity.class), 0);
		notification.setLatestEventInfo(context, "Title: "+title, "Location: "+content, contentIntent);
		
		nFm.notify(R.string.cut,notification);
		
	}
	
}
